home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / img / test / testview.py < prev    next >
Encoding:
Text File  |  2000-06-23  |  1.4 KB  |  61 lines

  1. import sys
  2. sys.path.insert(0, '..')
  3. import gl, GL, DEVICE
  4. import img
  5. import imgformat
  6. import imgconvert
  7.  
  8. imgconvert.settrace(1)
  9.  
  10. def view(title, fullname):
  11.         print 'Reading from',fullname,'...'
  12.     reader = img.reader(imgformat.rgb, fullname)
  13.     data = reader.read()
  14.     width = reader.width
  15.     height = reader.height
  16.     x1 = 10
  17.     x2 = x1 + width - 1
  18.     y2 = 1000
  19.     y1 = y2 - height + 1
  20.     gl.foreground()
  21.     gl.prefposition(x1, x2, y1, y2)
  22.     win = gl.winopen(title)
  23.     gl.RGBmode()
  24.     gl.gconfig()
  25.     gl.pixmode(GL.PM_TTOB, 1)
  26.  
  27.     gl.lrectwrite(0, 0, width-1, height-1, data)
  28.     gl.qdevice(DEVICE.REDRAW)
  29.     gl.qdevice(DEVICE.ESCKEY)
  30.     gl.qdevice(DEVICE.WINQUIT)
  31.     gl.qdevice(DEVICE.WINSHUT)
  32.     gl.qdevice(DEVICE.QKEY)
  33.     gl.qdevice(DEVICE.WKEY)
  34.     while 1:
  35.         dev, val = gl.qread()
  36.         if dev in (DEVICE.ESCKEY, DEVICE.QKEY, DEVICE.WKEY) and \
  37.               val == 0:
  38.             break
  39.         if dev in (DEVICE.WINSHUT, DEVICE.WINQUIT):
  40.             break
  41.         if dev == DEVICE.REDRAW:
  42.             gl.lrectwrite(0, 0, width-1, height-1, data)
  43.     gl.winclose(win)
  44.     if dev == DEVICE.WKEY:
  45.         import os
  46.         head, tail = os.path.split(fullname)
  47.         if not head:
  48.         head = '.'
  49.         newname = head + '/@copy-'+tail
  50.         print 'Writing to', newname,'...'
  51.         wrr = img.writer(imgformat.rgb, newname)
  52.         wrr.width, wrr.height = width, height
  53.         wrr.write(data)
  54.  
  55. args = sys.argv[1:]
  56. if not args:
  57.     print 'Usage:',sys.argv[0],'file ...'
  58. for a in args:
  59.     view(a, a)
  60.     
  61.